//
//  NSDate+YDYExtension.m
//  DYSisterAPP
//
//  Created by 杨德勇 on 16/8/6.
//  Copyright © 2016年 杨德勇. All rights reserved.
//

#import "NSDate+YDYExtension.h"
#import "NSCalendar+YDYExtension.h"

@implementation NSDate (YDYExtension)
-(BOOL)ydy_isThisYear{
    //获取今天
    NSDate *nowdate = [NSDate date];
    
    NSCalendar *cal = [NSCalendar ydy_calendar];
    //如果year有值，说明不是今年
    return ![cal components:NSCalendarUnitYear fromDate:self toDate:nowdate options:0].year;
    
    
    
}
-(BOOL)ydy_isThisMonth{
    //获取今天
    NSDate *nowdate = [NSDate date];
    //新建日历获取元素
    NSCalendar *cal = [NSCalendar ydy_calendar];
    
    NSCalendarUnit unit = NSCalendarUnitYear | NSCalendarUnitMonth |NSCalendarUnitDay|NSCalendarUnitHour|NSCalendarUnitMinute|NSCalendarUnitSecond;
    
    NSDateComponents *cps = [cal components:unit fromDate:self toDate:nowdate options:0];
    
    return cps.year == 0 && cps.month == 0;
    
    
}
-(BOOL)ydy_isToday{
    //获取今天
    NSDate *nowdate = [NSDate date];
    //新建日历获取元素
    NSCalendar *cal = [NSCalendar ydy_calendar];
    NSCalendarUnit unit = NSCalendarUnitYear | NSCalendarUnitMonth |NSCalendarUnitDay|NSCalendarUnitHour|NSCalendarUnitMinute|NSCalendarUnitSecond;
    NSDateComponents *cps = [cal components:unit fromDate:self toDate:nowdate options:0];
    
    return cps.year == 0 && cps.month == 0 &&cps.day ==0;
    
    
}

-(BOOL)ydy_isYesterday{
    //获取今天
    NSDate *nowdate = [NSDate date];
    //新建日历获取元素
    NSCalendar *cal = [NSCalendar ydy_calendar];
    NSCalendarUnit unit = NSCalendarUnitYear | NSCalendarUnitMonth |NSCalendarUnitDay|NSCalendarUnitHour|NSCalendarUnitMinute|NSCalendarUnitSecond;
    NSDateComponents *cps = [cal components:unit fromDate:self toDate:nowdate options:0];
    
    return cps.year == 0 && cps.month == 0 && cps.day == 1;
    
    
}
@end
